class Admin::CategoriesController < ApplicationController
  
  require_role 'admin'
  layout 'admin'
  
  def index
    @categories = Category.find(:all, :order => 'updated_at DESC')
  end
  
  def edit
    @category = Category.find(params[:id])
  end
  
  def update
    @category = Category.find(params[:id])
    if @category.update_attributes(params[:category])
      flash[:success] = 'Category updated'
      redirect_to :action => 'index'
    else
      render :action => 'edit', :id => @category
    end
  end
  
  def destroy
    @category = Category.find(params[:id])
    if @category.destroy
      flash[:success] = 'Category destroyed'
    end
    redirect_to :action => 'index'
  end
  
  def new
    @category = Category.new(params[:category])
  end
  
  def create
    @category = Category.create(params[:category])
    if @category
      flash[:success] = 'Category created'
      redirect_to :action => 'index'
    else
      render :action => 'new'
    end
  end
  
  
end